<template>
  <div :class="touchState?'record-button touched_btn':'record-button'" v-on="$listeners">
    <span>请按住说话</span>
    <div class="audio-wave">
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </div>
  </div>
</template>

<script>
    export default {
      name: 'recording',
      props: {
        touchState: {
          type:Boolean,
          required:true,
          default:false
        }
      },
      data() {
        return {
          touched:false,
          longPressTimer: null
        }
      },
      methods: {
      }
    }
</script>

<style scoped>
.record-button {
  width: 100%;
  height: 100%;
  background: none;
  border: none;
  color: #197bcc;
  font-size: 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.record-button:active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.audio-wave {
  position: absolute;
  top: 15%;
  left: 20%;
  width: 60%;
  height: 70%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  opacity: 0;
}

.audio-wave span {
  height: 20px; /* 初始高度 */
  width:4px;
  background-color: #2d82d1;
  border-radius: 2px;
  animation: none; /* 初始状态无动画 */
}


/* 定义不同音频线的动画 */
.audio-wave span:nth-child(1) { animation-duration: 0.3s; }
.audio-wave span:nth-child(2) { animation-duration: 0.4s; }
.audio-wave span:nth-child(3) { animation-duration: 0.5s; }
.audio-wave span:nth-child(4) { animation-duration: 0.6s; }
.audio-wave span:nth-child(5) { animation-duration: 0.7s; }
.audio-wave span:nth-child(6) { animation-duration: 0.8s; }
.audio-wave span:nth-child(7) { animation-duration: 0.9s; }
.audio-wave span:nth-child(8) { animation-duration: 0.4s; }
.audio-wave span:nth-child(9) { animation-duration: 0.5s; }
.audio-wave span:nth-child(10) { animation-duration: 0.6s; }
.audio-wave span:nth-child(11) { animation-duration: 0.3s; }
.audio-wave span:nth-child(12) { animation-duration: 0.4s; }
.audio-wave span:nth-child(13) { animation-duration: 0.5s; }
.audio-wave span:nth-child(14) { animation-duration: 0.6s; }
.audio-wave span:nth-child(15) { animation-duration: 0.7s; }
.audio-wave span:nth-child(16) { animation-duration: 0.8s; }
.audio-wave span:nth-child(17) { animation-duration: 0.9s; }
.audio-wave span:nth-child(18) { animation-duration: 0.4s; }
.audio-wave span:nth-child(19) { animation-duration: 0.5s; }
.audio-wave span:nth-child(20) { animation-duration: 0.6s; }

@keyframes audioWave {
  0%, 100% {
    height: 3px; /* 最小高度 */
  }
  50% {
    height: 25px; /* 最大高度 */
  }
}

.touched_btn .audio-wave {
  opacity: 1;
}

.touched_btn .audio-wave span {
  animation-name: audioWave;
  animation-iteration-count: infinite;
}

.touched_btn {
  color: transparent; /* 按钮按下时文字消失 */
}

</style>
